package it.davial.mgwt.client.mvp;

import it.davial.mgwt.client.ClientFactory;
import it.davial.mgwt.client.activities.about.AboutPlace;
import it.davial.mgwt.client.activities.menu.MenuActivity;
import it.davial.mgwt.client.activities.menu.MenuPlace;
import it.davial.mgwt.client.activities.patient.PatientPlace;
import it.davial.mgwt.client.activities.patient.detail.PatientDetailPlace;
import it.davial.mgwt.client.activities.picture.PicturePlace;
import it.davial.mgwt.client.activities.visit.VisitPlace;
import it.davial.mgwt.client.test.TestPlace;

import java.util.logging.Logger;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

public class TabletNavActivityMapper implements ActivityMapper {
	private static final Logger logger = Logger.getLogger("TabletNavActivityMapper");
	private final ClientFactory clientFactory;

	public TabletNavActivityMapper(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}
	
	private MenuActivity menu;

	@Override
	public Activity getActivity(Place place) {
		logger.info("TabletNavActivityMapper getting activity");
		if ( place instanceof MenuPlace ||
		     place instanceof AboutPlace ||
		     place instanceof PicturePlace ||
			 place instanceof VisitPlace ||
			 place instanceof PatientPlace ||
			 place instanceof PatientDetailPlace ||
			 place instanceof TestPlace){
			logger.info("place istanceof MenuPlace, returning MenuActivity");
			return getMenuActivity();
		}
		
	//	return getMenuActivity();
		return null;
	}
	
	private Activity getMenuActivity(){
		if ( menu == null )
			menu = new MenuActivity(clientFactory);
		return menu;
	}
}
